package comman.duke.display
{
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	/**
	 * ...
	 * @author jerry.d
	 */
	public class AnimsData 
	{
		public var texture:BitmapData;
		public var clipConfig:Object;
		public var groupName:String;
		public var resConfig:Object;
		public function AnimsData(group:String, texture:BitmapData, config:Object) 
		{
			this.groupName = group;
			this.texture = texture;
			this.clipConfig = {};
			this.resConfig = {};
			this.parse(config);
			this.copyRect = new Rectangle();
		}
		
		private function parse(data:Object):void{
			var clip:comman.duke.display.ClipData;
			for (var key:String in data['mc']){
				clip = new comman.duke.display.ClipData();
				clip.parseFrames(data['mc'][key]['frames']);
				this.clipConfig[key] = clip;
			}
			var resUnit:ResUnitData;
			var tdata:*;
			for (key in data['res']){
				tdata = data['res'][key];
				resUnit = new ResUnitData(tdata.x,tdata.t,tdata.w,tdata.h);
				this.resConfig[key] = resUnit;
			}
		}
		private var copyRect:Rectangle;
		public function render(bm:BitmapClip):void{
			var clip:ClipData = this.clipConfig[bm.animName];
			var currentFrame:uint = bm.currentFrame;
			var frame:FrameUnitData = clip.frames[currentFrame];
			var res:ResUnitData = this.resConfig[frame.res];
			this.copyRect.x = res.x;
			this.copyRect.y = res.y;
			this.copyRect.width = res.w;
			this.copyRect.height = res.h;
			bm.bitmapData = new BitmapData(res.w, res.h);
			//bm.bitmapData.width = res.w;
			//bm.bitmapData.height = res.h;
			
			bm.bitmapData.copyPixels(this.texture, this.copyRect, new Point(0, 0));
		}
	}

}